<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>信息修改</title>
    <link rel="stylesheet" href="../views/static/common/layui/css/layui.css">
    <link rel="stylesheet" href="../views/static/admin/css/style.css">
    <script src="../views/static/common/layui/layui.js"></script>
    <script src="../views/static/common/jquery-3.3.1.min.js"></script>
    <script src="../views/static/common/vue.min.js"></script>

    <script language="javascript">
        function sumbit_sure(){
            var gnl=confirm("是否确定修改?");
            if (gnl==true){
                return true;
            }else{
                return false;
            }
        }

        function loadData(){
            $("[name='vip_id']").append("<option selected value='${requestScope.vip.id}'>${requestScope.vip.name}</option>");

            $.post("${pageContext.request.contextPath}/BooksServlet.do", {"action": "loadData"}, function(data) {
                var homes = data.homes;
                for (let i = 0; i < homes.length; i++) {
                    var id = homes[i].id;
                    var num = homes[i].num;
                    var h_type = homes[i].h_type;
                    $("[name='home_id']").append("<option value='" + id + "'>" + num + "&nbsp;" + h_type + "</option>");
                }
            }, "json");
            $("[name='home_id']").append("<option selected value='${requestScope.home.id}'>${requestScope.home.num}&nbsp;${requestScope.home.h_type}</option>");

            $("[name='enterTime']").val("${requestScope.book.enterTime}");
            $("[name='exitTime']").val("${requestScope.book.exitTime}");
        }

        function checkExitTime(){
            let startTime =new Date($("input[name='enterTime']").val());
            let endTime = new Date($("input[name='exitTime']").val());
            if(endTime<startTime){
                $("input[name='exitTime']").next("span").text("退房时间必须大于入住时间");
                return false;
            }else{
                $("input[name='exitTime']").next("span").text("");
                return true;
            }
        }

        function updateBook(){
            var vip_id=$("[name='vip_id']").val();
            var home_id=$("[name='home_id']").val();
            var enterTime=$("[name='enterTime']").val();
            var exitTime=$("[name='exitTime']").val();

            if(vip_id=="" || home_id=="" || enterTime=="" || exitTime=="" ){
                layer.msg("请填写完整信息");
                return;
            }
            if(!checkExitTime()){
                return;
            }

            $.post("/BooksServlet.do",{
                "action":"updateBook",
                "id":"${requestScope.book.id}",
                "home_id":home_id,
                "enterTime":enterTime,
                "exitTime":exitTime
            },function(data){
                if(data){
                    alert("信息更改成功");
                    window.location.href = "${pageContext.request.contextPath}/views/guests_list.jsp";
                }else{
                    alert("信息更改失败失败，请稍后再试");
                }
            },"json");
        }
    </script>

</head>
<body onload="loadData();">
<div id="app" >
    <!--顶栏-->
    <header>
        <div style="float:left;"><img src="../views/static/admin/img/tubiao.png" width="152" height="55" /></div>
        <div style="float: right">
            <i  class="layui-icon  layui-anim layui-anim-rotate layui-anim-loop" style="font-size: 30px; color: #969baa;">&#xe614;</i>&nbsp; &nbsp; &nbsp;
        </div>
    </header>

    <div class="main" id="app">
        <!--左栏-->
        <div class="left">
            <ul class="cl" >
                <!--顶级分类-->
                <li v-for="vo,index in menu" :class="{hidden:vo.hidden}">
                    <a href="javascript:;"  :class="{active:vo.active}"  @click="onActive(index)">
                        <i class="layui-icon" v-html="vo.icon"></i>
                        <span v-text="vo.name"></span>
                        <i class="layui-icon arrow" v-show="vo.url.length==0">&#xe61a;</i> <i v-show="vo.active" class="layui-icon active">&#xe623;</i>
                    </a>
                    <!--子级分类-->
                    <div v-for="vo2,index2 in vo.list">
                        <a href="javascript:;" :class="{active:vo2.active}" @click="onActive(index,index2)" v-text="vo2.name"></a>
                        <i v-show="vo2.active" class="layui-icon active">&#xe623;</i>
                    </div>
                </li>
            </ul>
        </div>
        <!--右侧-->
        <div class="right">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>信息修改</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">入住会员</label>
                <div class="layui-input-block">
                    <select name="vip_id" class="layui-input" autocomplete="off" required >

                    </select>
                </div>
            </div>

            <div class="layui-form-item" >
                <label class="layui-form-label">入住时间</label>
                <div class="layui-input-block" >
                    <input type="date" name="enterTime" required id="getTime"  autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">退房时间</label>
                <div class="layui-input-block">
                    <input type="date" name="exitTime" required  id="" autocomplete="off" onblur="checkExitTime()" class="layui-input">
                    <span style="color: red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">房间号</label>
                <div class="layui-input-block">
                    <select name="home_id" class="layui-input" autocomplete="off" required >

                    </select>
                </div>
            </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" class="layui-btn" onclick="updateBook();" value="确认修改" />
                        <input type="button" class="layui-btn layui-btn-danger"  value="取消修改" onclick="javascript:history.go(-1);"/>
                        <input name="id" value="${g.id}" type="hidden"/>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<script src="../views/static/admin/js/config.js"></script>
<script src="../views/static/admin/js/script.js"></script>
</body>
</html>
